<style type="text/css">
.pageFormContent tr { height:25px}
.pageFormContent tr label { width:65px}
</style>
<script language="javascript" type="text/javascript">

/*
   * 引用 dmt_plugin.html 变量: <?cs var:config.plugin_pre ?>_sel_plugin
   */

var g_ddap_mod_attr = false;
var g_ddap_mod_attr_type = false;
var g_ddap_mod_cfg = false;
var ddapFormSplit = "---------------------------------------------------------------------------";
var ddapFormCss = '';
ddapFormCss = '<style type="text/css">';
ddapFormCss += '.ddapFormItemSel { background-color:#2894FF }';
ddapFormCss += '</style>';

$(document).ready(function(){

	$('#ddap_src_url').click(function() {
		if($(this).attr('href') == '#') {
			alertMsg.info('未设置源码链接地址，请先设置');
			return false;
		}
		return true;
	});

	$("#ddap_open_src").change(function() {
		if($("#ddap_open_src").val() == 1)
			$('#ddap_src_url_show').css('display', 'block');
		else
			$('#ddap_src_url_show').css('display', 'none');
	});

	$('#ddap_btn_view_attr_type').click(function() {
		$('#ddap_dlg_show_attr_type table tbody').html('');
		var fhtml = "";
		$('#ddap_attr_types option').each(function(){
			if(this.value == 0)
				return;

			fhtml += "<tr>";
			<?cs if:config.action == 'show_local_mt_plugin' ?>
			fhtml += "<td align='left' style='width:50px' valign='top'>" + $(this).attr('attrid') + "</td>";
			<?cs else ?>
			fhtml += "<td align='left' style='width:50px' valign='top'>0</td>";
			<?cs /if ?>
			fhtml += "<td align='left' style='width:50px' valign='top'>" +  this.value + "</td>";
			fhtml += "<td align='left' valign='top' style='width:200px'>" + $(this).attr('myname') + "</td>";
			fhtml += "<td align='left' valign='top' style='width:200px'>" + $(this).attr('mydesc') + "</td>";
			fhtml += "</tr>";
		});
		$('#ddap_dlg_show_attr_type table tbody').html(fhtml);
		var op = { mask:true, maxable:false, height:280, width:560, resizable:false, drawable:true};
		$.pdialog.openLocal('ddap_dlg_show_attr_type', 
			'dlg_ddap_dlg_show_attr_type', '插件监控点类型查看', op);
	});

	var dp_sel_plugin = <?cs var:config.plugin_pre ?>_sel_plugin;
	if(dp_sel_plugin == null || dp_sel_plugin.plugin_id != <?cs var:config.plugin_id ?>) {
		alertMsg.warn("脚本运行错误, 请刷新页面重试");
		return;
	}
	$('#ddap_plugin_name').val(dp_sel_plugin.plugin_name);

	$("#ddap_open_src option").each(function() {
		if(this.value == dp_sel_plugin.open_src) {
			$(this).attr("selected", true);
			return false;
		}
	});

	$('#ddap_dev_language option').each(function() {
		if(this.value == dp_sel_plugin.dev_language) {
			$(this).attr("selected", true);
			return false;
		}
	});

	$('#ddap_set_method option').each(function() {
		if(this.value == dp_sel_plugin.set_method) {
			$(this).attr("selected", true);
			return false;
		}
	});

	$('#ddap_dest_os option').each(function() {
		if(this.value == dp_sel_plugin.dest_os) {
			$(this).attr("selected", true);
			return false;
		}
	});

	ddapGetPluginPbInfo();

	if(dp_sel_plugin.pic != "" && dp_sel_plugin.pic != null)  {
		$('#ddap_plugin_pic').attr('src', '<?cs var:config.xrkmonitor_url?>/monitor/download/plugin/'+dp_sel_plugin.pic);
	}
	else {
		$('#ddap_plugin_pic').attr('src', '<?cs var:config.xrkmonitor_url?>/monitor/download/plugin/plugin_def_pic.png');
	}
});

function ddapSetPluginInfo(js)
{
	var attrtype = $('#ddap_attr_types');
	if(typeof js.attr_types != 'undefined' && js.attr_types != null) {
		attrtype.html("");
		for(var i=js.attr_types.length-1; i >= 0; i--) {
			var op = $('<option></option>');
			op.text(js.attr_types[i].attr_type_name+' ('+js.attr_types[i].plug_attr_type_id+')');
			op.val(js.attr_types[i].plug_attr_type_id);
			op.attr('attrid', js.attr_types[i].attr_type_id);
			op.attr('myname', js.attr_types[i].attr_type_name);
			op.attr('mydesc', js.attr_types[i].attr_type_desc);
			if(i==0)
				op.attr('selected', true);
			attrtype.append(op);
		}
	}

	var fhtml = "";
	if(typeof js.attrs != 'undefined' && js.attrs != null) {
		fhtml = ddapFormCss;
		fhtml += "<div id='ddap_plugin_attr' style='padding-left:5px; overflow-x:hidden;'>";
		fhtml += "插件监控点如下共 (<font id='dapmar_count'>"+js.attrs.length+"</font>) 个: <br />";
		fhtml += ddapFormSplit; 
		fhtml += "<table class='list' style='word-break:break-all; word-wrap:break-all;'>";
		fhtml += "<thead><tr>"
		fhtml += "<th align='left' valign='top' style='width:10%'>AID</th>";
		fhtml += "<th align='left' valign='top' style='width:10%'>PAID</th>";
		fhtml += "<th align='left' valign='top' style='width:6%'>TID</th>";
		fhtml += "<th align='left' valign='top' style='width:5%'>DT</th>";
		fhtml += "<th align='left' valign='top' style='width:24%'>监控点名称</th>";
		fhtml += "<th align='left' valign='top' style='width:20%'>监控点宏名</th>";
		fhtml += "<th align='left' valign='top' style='width:35%'>监控点描述</th>";
		fhtml += "</tr></thead><tbody>";

		for(var i=js.attrs.length-1; i >= 0; i--) {
			fhtml += "<tr>"; 
			<?cs if:config.action == 'show_local_mt_plugin' ?>
			fhtml += "<td align='left' valign='top'>" + js.attrs[i].attr_id + "</td>";
			<?cs else ?>
			fhtml += "<td align='left' valign='top'>0</td>";
			<?cs /if ?>

			fhtml += "<td align='left' valign='top'>"+js.attrs[i].plug_attr_id+"</td>";
			fhtml += "<td align='left' valign='top'>"+js.attrs[i].plug_attr_type_id+"</td>";
			fhtml += "<td align='left' valign='top'>"+js.attrs[i].attr_data_type+"</td>";
			fhtml += "<td align='left' valign='top'>"+js.attrs[i].attr_name+"</td>";
			fhtml += "<td align='left' valign='top'>"+js.attrs[i].attr_id_macro+"</td>";
			fhtml += "<td align='left' valign='top'>"+js.attrs[i].attr_desc+"</td>";
			fhtml += "</tr>";
		}
		fhtml += "</tbody></table>";
		fhtml += ddapFormSplit; 
		document.getElementById("ddap_up_file_info").contentDocument.body.innerHTML = fhtml;
	}

	if(typeof js.cfgs != 'undefined' && js.cfgs != null) {
		fhtml = "<div id='ddap_plugin_cfg' style='padding-left:5px; overflow-x:hidden;'>";
		fhtml += "插件配置如下共 (<font id='dapmar_cfgs'>"+js.cfgs.length+"</font>) 个: <br />";
		fhtml += ddapFormSplit; 
		fhtml += "<table class='list' style='word-break:break-all; word-wrap:break-all;'><thead><tr>";
		fhtml += "<th align='left' valign='top' style='width:30%'>配置名称</th>";
		fhtml += "<th align='left' valign='top' style='width:30%'>配置值</th>";
		fhtml += "<th align='left' valign='top' style='width:10%'>MDF</th>";
		fhtml += "<th align='left' valign='top' style='width:40%'>配置说明</th>";
		fhtml += "</tr></thead><tbody>";

		for(var i=js.cfgs.length-1; i >= 0; i--) {
			fhtml += "<tr>";
			fhtml += "<td align='left' valign='top'>"+js.cfgs[i].item_name+"</td>";
			fhtml += "<td align='left' valign='top'>"+js.cfgs[i].item_value+"</td>";
			fhtml += "<td align='left' valign='top'>"+js.cfgs[i].enable_modify+"</td>";
			fhtml += "<td align='left' valign='top'>"+js.cfgs[i].item_desc+"</td>";
			fhtml += "</tr>";
		}
		fhtml += "</tbody></table>";
		fhtml += ddapFormSplit; 
	
		var sAttrDiv = $("#ddap_up_file_info").contents().find("#ddap_plugin_attr");
		if(typeof sAttrDiv != 'undefined' && sAttrDiv != null && sAttrDiv.length > 0)
			sAttrDiv.before(fhtml);
		else 
			document.getElementById("ddap_up_file_info").contentDocument.body.innerHTML 
				= ddapFormCss+fhtml;

		var $trs = $("#ddap_up_file_info").contents().find('#ddap_plugin_cfg table tbody >tr');
		$trs.each(function() {
			$(this).click(function() {
				var $ftrs= $("#ddap_up_file_info").contents().find('#ddap_plugin_cfg tbody >tr');
				$ftrs.filter(".ddapFormItemSel").removeClass("ddapFormItemSel");
				$(this).addClass("ddapFormItemSel");
			});
		});
	}

	if(typeof js.plus_url != 'undefined' && js.plus_url != '' && js.b_open_source) {
		$('#ddap_src_url_show').css('display', 'block');
		$('#ddap_in_src_url').val(js.plus_url);
		$('#ddap_src_url').attr('href', js.plus_url);
	}
	else
		$('#ddap_src_url_show').css('display', 'none');

	$('#ddap_plugin_ver').val(js.plus_version);
	$('#ddap_plugin_auth').val(js.plugin_auth);
	if(js.b_add_log_module == 1)
		$('#ddap_log_check').attr('checked', true).attr('disabled', true);
	if(typeof js.plus_desc != 'undefined')
		$('#ddap_desc').text(js.plus_desc.replace(/&br/g, "\r\n"));
}

function ddapGetPluginPbInfo()
{
	<?cs if:config.action == 'show_local_mt_plugin' ?>

	var jstxt = '<?cs var:config.plugin_info ?>';
	if(jstxt == 'null')
		return;
	setTimeout(function() {
		ddapSetPluginInfo($.parseJSON(jstxt));
	}, 100);

	<?cs else ?>

	var requrl = "<?cs var:config.xrkmonitor_url?>/cgi-bin/mt_slog_open?action=open_get_plugin_pb_info";
	requrl += "&plugin_id=<?cs var:config.plugin_id ?>";
	$.ajax({
		type: "get",
		url: requrl,
		dataType: 'json', 
		global: false,
		timeout: function(){
			alertMsg.warn("请求超时");
		},
		success: function(js){
			if(dmtFirstDealAjaxResponse(js))
				return;
			ddapSetPluginInfo(js);
		}
	});

	<?cs /if ?>
}

</script>


<div id='ddap_dlg_show_attr_type' style='display:none'>
	<table class='list' style='word-break:break-all; word-wrap:break-all;'>
		<thead>
			<th align='left' valign='top' style='width:100px'>系统编号</th>
			<th align='left' valign='top' style='width:100px'>插件内编号</th>
			<th align='left' valign='top' style='width:200px'>类型名称</th>
			<th align='left' valign='top' style='width:200px'>类型描述</th>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>

<div class="pageContent">
	<div class="pageFormContent" layoutH="56">
		<table>
			<tr>
			<td>
				<label>插件名称：</label>
				<input type="text" class="required" size="24" name="ddap_plugin_name" id="ddap_plugin_name" value="<?cs var:config.ddap_plugin_name ?>" readonly minlength="6" maxlength="28" /> 
			</td>
			<td>
				<div style='float:left'>
				<select name="ddap_attr_types" id="ddap_attr_types" style='width:185px;float:right;'>
					<option value="0">-请选择-</option>
				</select> 
				</div>

				<div style='float:left'>
    			<input type="button" value="查看监控点类型" id='ddap_btn_view_attr_type' />
				</div>
			</td>
			</tr>

			<tr>
			<td> 
				<label>插件版本：</label>
				<input type="text" class="required" size="12" name="ddap_plugin_ver" id="ddap_plugin_ver" value="<?cs var:config.plugin_ver ?>" minlength="6" maxlength="12" />
			</td>
			<td rowspan="10">
				<div> 
					<iframe style='margin-top:1px' src='' name='ddap_up_file_info' id='ddap_up_file_info' height='470' width='610'></iframe>
				</div>
			</td>
			</tr>

			<tr>
			<td> 
				<label>开发者：</label>
				<?cs if:comm.user_type == 4 || comm.user_type == 1 ?>
				<input type="text" size="20" name="ddap_plugin_auth" id="ddap_plugin_auth" value="官方" readonly disabled />
				<?cs else ?>
				<input type="text" size="20" name="ddap_plugin_auth" id="ddap_plugin_auth" value="<?cs var:comm.user_name ?>" readonly disabled />
				<?cs /if ?>
			</td>
			</tr>

			<tr>
			<td> 
				<label>是否开源：</label>
				<select name="ddap_open_src" id="ddap_open_src">
					<option value="1">开源</option>
					<option value="0">闭源</option>
				</select>
				<span id='ddap_src_url_show'>
					<a href='#' id='ddap_src_url' target='_blank'>
						<font style='color:blue;margin-top:2px'>查看源码</font>
					</a>
					<input id='ddap_in_src_url' name='ddap_in_src_url' type='hidden' value=''>
				</span>
			</td>
			</tr>

			<tr>
			<td> 
				<label>部署方式：</label>
				<select name="ddap_set_method" id="ddap_set_method">
					<option value="0">内置</option>
					<option value="1">外置</option>
				</select>
			</td>
			</tr>

			<tr>
			<td> 
				<label>开发语言：</label>
				<select name="ddap_dev_language" id="ddap_dev_language">
					<option value="c/c++">c/c++</option>
					<option value="php">php</option>
					<option value="linux shell">linux shell</option>
					<option value="javascript">javascript</option>
					<option value="java">java</option>
					<option value="python">python</option>
				</select>
			</td>
			</tr>

			<tr>
			<td> 
				<label>运行平台：</label>
				<select name="ddap_dest_os" id="ddap_dest_os">
					<option value="Linux">Linux</option>
					<option value="Windows">Windows</option>
				</select>
			</td>
			</tr>

			<tr>
			<td>
				<label for='ddap_log_check'>日志配置：</label>
				<input type="checkbox" name="ddap_log_check" id="ddap_log_check">
				<font class="note-text">
				<label style="float:right;width:160px" for='ddap_log_check'>为插件添加模块和日志配置</label>
				</font>
			</td>
			</tr>

			<tr>
			<td style="height:90px;">
				<label>插件描述：</label>
				<textarea rows="5" cols="25" id='ddap_desc' name="ddap_desc" class='required' minlength="1" maxlength="120"></textarea>
			</td>
			</tr>

			<tr>
			<td style="height:90px;">
				<label>图片预览：</label>
				<img id="ddap_plugin_pic" width='160px' height='160px'></img>
			</td>
			</tr>
		</table>

	</div>

		<div class="formBar">
			<ul>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">&nbsp;&nbsp;关&nbsp;闭&nbsp;&nbsp;</button></div></div>
				</li>
			</ul>
		</div>
</div>

